package fun.sboy.headacheMemo.service.impl;

import fun.sboy.headacheMemo.entry.User;
import fun.sboy.headacheMemo.mapper.UserMapper;
import fun.sboy.headacheMemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(User user) {
        //密码使用md5进行加密
        String passwd = DigestUtils.md5DigestAsHex(user.getPasswd().getBytes(StandardCharsets.UTF_8));
        User userSelect = userMapper.login(user.getUname(), passwd);
        return userSelect;
    }

    @Override
    public void register(User user) {
        //密码使用MD5加密
        user.setPasswd(DigestUtils.md5DigestAsHex(user.getPasswd().getBytes(StandardCharsets.UTF_8)));
        userMapper.register(user);
    }
}
